﻿using UnityEngine;
using System.Collections;

public class Avatar2 : MonoBehaviour {

	public Motor[] motors;
	public Neuron[] motorNeurons;
	
	public Sensor[] sensors;
	public Neuron[] sensorNeurons;
	
	void Start() {

		int c;

		c = 0;
		foreach (Motor m in gameObject.GetComponentsInChildren<Motor>()) {
			Neuron n = m.gameObject.GetComponentInChildren<Neuron>();
			if (n != null) {
				motors[c] = m;
				motorNeurons[c] = n;
				c++;
			}
		}
		c = 0;
		foreach (Sensor s in gameObject.GetComponentsInChildren<Sensor>()) {
			Neuron n = s.gameObject.GetComponentInChildren<Neuron>();
			if (n != null) {
				sensors[c] = s;
				sensorNeurons[c] = n;
				c++;
			}
		}

	}
	
	void FixedUpdate() {
		for (int i = 0; i < motors.Length; i++) {
			motors[i].inputValue = motorNeurons[i].axon;
		}
		for (int i = 0; i < sensors.Length; i++) {
			sensorNeurons[i].synapse = sensors[i].output;
		}
	}
}